package logic

import (
	"B/models/mysql"
	"context"
	"fmt"

	"B/internal/svc"
	"B/shenzhousrv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAuditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAuditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAuditLogic {
	return &GoodsAuditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAuditLogic) GoodsAudit(in *shenzhousrv.GoodsAuditRequest) (*shenzhousrv.GoodsAuditResponse, error) {
	// todo: add your logic here and delete this line

	var goods mysql.Goods
	err := goods.FindGoods(int(in.GoodsId))
	if err != nil {
		return nil, fmt.Errorf("商品不存在")
	}
	goods.Status = in.Status
	err = goods.UpdateGoods()
	if err != nil {
		return nil, fmt.Errorf("审核失败")
	}

	return &shenzhousrv.GoodsAuditResponse{}, nil
}
